eval([strcat('load MAT/rho',rhoT,'eta',etaT,'lambda',lambdaT,'_psi',num2str(varphi),'_sigma',num2str(sigmaT),'/Step_5_output_alpha',num2str(alphaT),...
         '_rho',rhoT,'_',shockT,'_approx.mat')]); 
w_f = VA_fj_0/sum(VA_fj_0);
RGDP_doubledef_hat_fj(isnan(RGDP_doubledef_hat_fj)==1)=1;
dlnY_f = (RGDP_doubledef_hat_fj-1)*100;

load 'MAT/WIOD.mat';
load 'MAT/Step_2_firm_data_alpha4';
eval([strcat('load MAT/rho',rhoT,'eta',etaT,'lambda',lambdaT,'_psi',num2str(varphi),'_sigma',num2str(sigmaT),'/Step_4_setup_alpha',num2str(alphaT),...
         '_rho',rhoT,'_approx.mat')]); 
gamma_IM = 1-sum(GAMMA_sorted_matrix(:,start(france):start(france+1)-1),2);
X_mnjf_0 = firmsecD_sorted*X_mnj(start(france):start(france+1)-1,:);
X_mnjf_0=full(pi_mnjf.*X_mnjf_0);
sales = sum(X_mnjf_0,2);
ex_rat = (sales-X_mnjf_0(:,15))./sales;
ex_rat(isnan(ex_rat)==1)=0;
IM = zeros(FI_J,1);
IM(gamma_IM>1e-06) = 1;
EX = zeros(FI_J,1);
EX(ex_rat>1e-06) = 1;
EXIM = zeros(FI_J,1);
EXIM(IM==1 & EX==1) = 1;
IM(EXIM==1) = 0;
EX(EXIM==1) = 0;

freq_EX = sum(EX)/FI_J;
freq_IM = sum(IM)/FI_J;
freq_EXIM = sum(EXIM)/FI_J;
freq_NO = 1-freq_EX-freq_IM-freq_EXIM;
w_EX = sum(EX.*w_f);
w_IM = sum(IM.*w_f);
w_EXIM = sum(EXIM.*w_f);
w_NO = 1-w_EX-w_IM-w_EXIM;
el_EX = sum(EX.*w_f.*dlnY_f);
el_IM = sum(IM.*w_f.*dlnY_f);
el_EXIM = sum(EXIM.*w_f.*dlnY_f);
el_tot = sum(w_f.*dlnY_f);
el_NO = el_tot - el_EX-el_IM-el_EXIM;
share_el_EX = el_EX./el_tot;
share_el_IM = el_IM./el_tot;
share_el_EXIM = el_EXIM./el_tot;
share_el_NO = el_NO./el_tot;
figure3 = figure(3)
axes1 = axes('Parent',figure3);
hold(axes1,'on');
X = categorical({'Exporter','Importer','Exporter+Importer','Domestic'});
X = reordercats(X,{'Exporter','Importer','Exporter+Importer','Domestic'});
y = [freq_EX freq_EXIM freq_IM freq_NO;w_EX w_EXIM w_IM w_NO;share_el_EX share_el_EXIM share_el_IM share_el_NO];
bar1 = bar(X,y);
set(bar1(3),'DisplayName','Elasticity share');
set(bar1(2),'DisplayName','Value share');
set(bar1(1),'DisplayName','Frequency share');
box(axes1,'on');
hold(axes1,'off');
legend(axes1,'show','Location','northwest');
fig3=strcat('Figures/rho',rhoT,'eta',etaT,'lambda',lambdaT,'_psi',num2str(varphi),'_sigma',num2str(sigmaT),'/Fig3.eps');
saveas(gcf,fig3,'epsc2')
